// 夜审相关API接口

// 夜审订单类型
export interface NightAuditOrder {
  id: number;
  orderNo: string;
  guestName: string;
  roomNo: string;
  checkInTime: string;
  checkOutTime: string;
  status: string;
  amount: number;
  type: string;
  guestPhone?: string;
  guestIdCard?: string;
  deposit?: number;
  consumption?: number;
  paymentMethod?: string;
  remarks?: string;
}

// 夜审处理项目类型
export interface AuditItem {
  id: number;
  title: string;
  icon: string;
  color: string;
  count: number;
  status: 'pending' | 'completed';
  description?: string;
}

// 夜审查询参数
export interface NightAuditQueryParams {
  status?: string;
  type?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  pageSize?: number;
}

// 夜审统计信息
export interface NightAuditStatistics {
  totalOrders: number;
  pendingOrders: number;
  completedOrders: number;
  totalAmount: number;
  overdueCount: number;
  noShowCount: number;
  hourlyCount: number;
  maintenanceCount: number;
}

// 入账信息
export interface AccountEntry {
  orderId: number;
  type: 'payment' | 'consumption' | 'pre_authorization' | 'small_goods';
  amount: number;
  method: string;
  description?: string;
}

// API函数
export const nightAuditApi = {
  // 获取夜审处理项目列表
  getAuditItems: () => {
    return Promise.resolve([
      {
        id: 1,
        title: '逾期退房',
        icon: 'ant-design:clock-circle-outlined',
        color: '#ff4d4f',
        count: 5,
        status: 'pending' as const,
        description: '超过退房时间未退房的订单',
      },
      {
        id: 2,
        title: '未到店订单',
        icon: 'ant-design:user-delete-outlined',
        color: '#faad14',
        count: 3,
        status: 'pending' as const,
        description: '预订但未到店的订单',
      },
      {
        id: 3,
        title: '钟点房到期',
        icon: 'ant-design:hourglass-outlined',
        color: '#1890ff',
        count: 8,
        status: 'pending' as const,
        description: '钟点房使用时间到期的订单',
      },
      {
        id: 4,
        title: '维修房到期',
        icon: 'ant-design:tool-outlined',
        color: '#52c41a',
        count: 2,
        status: 'completed' as const,
        description: '维修房维修时间到期的房间',
      },
      {
        id: 5,
        title: '房租预审',
        icon: 'ant-design:calculator-outlined',
        color: '#722ed1',
        count: 12,
        status: 'pending' as const,
        description: '需要预审房租的订单',
      },
    ]);
  },

  // 获取夜审订单列表
  getOrders: (params: NightAuditQueryParams = {}) => {
    const mockOrders: NightAuditOrder[] = [
      {
        id: 1,
        orderNo: 'HT20241216001',
        guestName: '张三',
        roomNo: '101',
        checkInTime: '2024-12-16 14:00',
        checkOutTime: '2024-12-17 12:00',
        status: 'overdue',
        amount: 299,
        type: 'overdue',
        guestPhone: '13800138001',
        guestIdCard: '110101199001011234',
        deposit: 500,
        consumption: 50,
        paymentMethod: '现金',
        remarks: '客人要求延迟退房',
      },
      {
        id: 2,
        orderNo: 'HT20241216002',
        guestName: '李四',
        roomNo: '205',
        checkInTime: '2024-12-16 15:00',
        checkOutTime: '2024-12-16 18:00',
        status: 'no_show',
        amount: 150,
        type: 'no_show',
        guestPhone: '13800138002',
        guestIdCard: '110101199002022345',
        deposit: 200,
        consumption: 0,
        paymentMethod: '微信支付',
        remarks: '客人未到店',
      },
      {
        id: 3,
        orderNo: 'HT20241216003',
        guestName: '王五',
        roomNo: '308',
        checkInTime: '2024-12-16 10:00',
        checkOutTime: '2024-12-16 14:00',
        status: 'hourly',
        amount: 120,
        type: 'hourly',
        guestPhone: '13800138003',
        guestIdCard: '110101199003033456',
        deposit: 150,
        consumption: 30,
        paymentMethod: '支付宝',
        remarks: '钟点房正常使用',
      },
      {
        id: 4,
        orderNo: 'HT20241216004',
        guestName: '赵六',
        roomNo: '401',
        checkInTime: '2024-12-15 14:00',
        checkOutTime: '2024-12-16 12:00',
        status: 'maintenance',
        amount: 399,
        type: 'maintenance',
        guestPhone: '13800138004',
        guestIdCard: '110101199004044567',
        deposit: 500,
        consumption: 80,
        paymentMethod: '银行卡',
        remarks: '维修房到期',
      },
    ];

    let filteredOrders = mockOrders;

    // 根据状态过滤
    if (params.status) {
      filteredOrders = filteredOrders.filter(
        (order) => order.status === params.status,
      );
    }

    // 根据类型过滤
    if (params.type) {
      filteredOrders = filteredOrders.filter(
        (order) => order.type === params.type,
      );
    }

    return Promise.resolve({
      list: filteredOrders,
      total: filteredOrders.length,
      page: params.page || 1,
      pageSize: params.pageSize || 10,
    });
  },

  // 获取夜审统计信息
  getStatistics: () => {
    return Promise.resolve({
      totalOrders: 30,
      pendingOrders: 18,
      completedOrders: 12,
      totalAmount: 8500,
      overdueCount: 5,
      noShowCount: 3,
      hourlyCount: 8,
      maintenanceCount: 2,
    });
  },

  // 开始夜审
  startNightAudit: () => {
    return Promise.resolve({
      success: true,
      message: '夜审处理已开始',
      processedCount: 0,
    });
  },

  // 批量处理订单
  batchProcessOrders: (orderIds: number[]) => {
    return Promise.resolve({
      success: true,
      message: `成功处理 ${orderIds.length} 个订单`,
      processedCount: orderIds.length,
    });
  },

  // 处理单个订单
  processOrder: (orderId: number, action: string) => {
    return Promise.resolve({
      success: true,
      message: `订单 ${orderId} 处理成功`,
      action,
    });
  },

  // 入账
  accountEntry: (entry: AccountEntry) => {
    return Promise.resolve({
      success: true,
      message: '入账成功',
      entryId: Date.now(),
    });
  },
};
